// 秒杀商品Mapper
package com.heima.mapper;

import com.heima.entity.SeckillGoods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SeckillGoodsMapper {

    @Select("SELECT * FROM seckill_goods WHERE goods_id = #{goodsId}")
    SeckillGoods getSeckillGoodsByGoodsId(@Param("goodsId") long goodsId);

    @Update("UPDATE seckill_goods SET stock_count = stock_count - 1 WHERE goods_id = #{goodsId} AND stock_count > 0")
    int reduceStock(@Param("goodsId") long goodsId);

    // 查询所有有效的秒杀商品
    @Select("SELECT * FROM seckill_goods WHERE end_date > NOW()")
    List<SeckillGoods> selectAllValidSeckillGoods();
}
